package cn.yunhe.pojo;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity(name = "课程")
@Table(name = "course")
public class Course implements Serializable {
    private int cid;
    private String cname;
    private Set<Student> studentSet=new HashSet<>();

    public Course() {
    }

    public Course(String cname) {
        this.cname = cname;
    }

    public Course(String cname, Set<Student> studentSet) {
        this.cname = cname;
        this.studentSet = studentSet;
    }

    public Course(int cid, String cname, Set<Student> studentSet) {
        this.cid = cid;
        this.cname = cname;
        this.studentSet = studentSet;
    }


    @Id
    @GeneratedValue
    @Column(name = "cid")
    public int getCid() {
        return cid;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }

    @Column(name = "cname")
    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinTable(name ="m_course_student",
            joinColumns = @JoinColumn(name = "mcid"),
            inverseJoinColumns = @JoinColumn(name="msid")
    )
    public Set<Student> getStudentSet() {
        return studentSet;
    }

    public void setStudentSet(Set<Student> studentSet) {
        this.studentSet = studentSet;
    }
}
